package com.wpp.basespringmongodb.dao.impl;

import com.wpp.basespringmongodb.dao.ResumeDao;
import com.wpp.basespringmongodb.po.ResumePO;
import com.wpp.mongodb.common.Constants;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wpp25
 * @date 2021/6/19 21:48
 * @description：
 */
@Repository("resumeDao")
public class ResumeDaoImpl implements ResumeDao {

    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public void insertResume(ResumePO resumePO) {
        mongoTemplate.insert(resumePO, Constants.COLLECTION);
    }

    @Override
    public List<ResumePO> queryByName(String name) {
        Query query = new Query();
        query.addCriteria(Criteria.where("name").is(name));

        return mongoTemplate.find(query, ResumePO.class,Constants.COLLECTION);
    }

    @Override
    public List<ResumePO> queryByNameAndCity(String name, String city) {
        Query query = new Query();
        query.addCriteria(Criteria.where("name").is(name).andOperator(Criteria.where("city").is(city)));

        return mongoTemplate.find(query, ResumePO.class, Constants.COLLECTION);
    }

    @Override
    public List<ResumePO> queryBySalaryAndCity(int salary, String city) {
        Query query = new Query();
        query.addCriteria(Criteria.where("expectSalary").gt(salary).andOperator(Criteria.where("city").is(city)));

        return mongoTemplate.find(query, ResumePO.class, Constants.COLLECTION);
    }
}
